package org.maylove.wuziqi.service;

import org.maylove.wuziqi.game.GameManager;
import org.maylove.wuziqi.pojo.game.dto.GameRoomDto;
import org.maylove.wuziqi.pojo.game.dto.GameRoomPlayerDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

@Service
public class GameServiceImpl implements GameService {

    @Autowired
    ApplicationEventPublisher eventPublisher;

    @Override
    public String prepare(Integer roomId, Long userId) {
        GameManager gameManager = GameManager.getInstance(eventPublisher);
        return gameManager.prepare(roomId, userId);
    }

    @Override
    public GameRoomDto get(Long userId, Integer roomId) {
        GameManager gameManager = GameManager.getInstance(eventPublisher);
        return gameManager.get(userId, roomId);
    }

    @Override
    public String game(Long userId, Integer roomId, Integer x, Integer y) {
        GameManager gameManager = GameManager.getInstance(eventPublisher);
        return gameManager.game(userId, roomId, x, y);
    }

    @Override
    public GameRoomPlayerDto get(Integer roomId) {
        GameManager gameManager = GameManager.getInstance(eventPublisher);
        return gameManager.get(roomId);
    }

    @Override
    public String back(Long userId, Integer roomId) {
        GameManager gameManager = GameManager.getInstance(eventPublisher);
        return gameManager.back(userId, roomId);
    }

    @Override
    public String giveUp(Long userId, Integer roomId) {
        GameManager gameManager = GameManager.getInstance(eventPublisher);
        return gameManager.giveUp(userId, roomId);
    }

    @Override
    public void cleanRoom(Integer roomId) {
        GameManager gameManager = GameManager.getInstance(eventPublisher);
        gameManager.cleanRoom(roomId);
    }

    @Override
    public void free(int roomId) {
        GameManager gameManager = GameManager.getInstance(eventPublisher);
        gameManager.free(roomId);
    }

    @Override
    public String exit(Long userId, Integer roomId) {
        GameManager gameManager = GameManager.getInstance(eventPublisher);
        return gameManager.exit(userId, roomId);
    }

    @Override
    public String trans(Long userId, Integer roomId) {
        GameManager gameManager = GameManager.getInstance(eventPublisher);
        return gameManager.trans(userId, roomId);
    }

    @Override
    public Integer[][] getBoard(Integer roomId) {
        GameManager gameManager = GameManager.getInstance(eventPublisher);
        return gameManager.getBoard(roomId);
    }
}
